package auxiliary;

import java.awt.Component;
import java.awt.Container;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.swing.JFrame;

import org.joda.time.DateTime;

public class Constants {

	public final static String PLAN = "plan";
	public final static String FUNCIONARIO = "funcionario";
	public final static String MAQUINARIA = "maquinaria";
	public final static String PRODUCCION = "produccion";

	public final static String PLAN_ACTUALIZAR = "plan_actualizar";
	public final static String PLAN_GENERAR_PDF = "plan_generar_pdf";
	public final static String PLAN_MOSTRAR = "plan_mostrar";

	public final static String FUNCIONARIO_AGREGAR = "funcionario_agregar";
	public final static String FUNCIONARIO_AGREGAR_CANCELAR = "funcionario_agregar_cancelar";
	public final static String FUNCIONARIO_AGREGAR_CONFIRMACION = "funcionario_agregar_confirmacion";
	public final static String FUNCIONARIO_ELIMINAR = "funcionario_eliminar";
	public final static String FUNCIONARIO_MODIFICAR = "funcionario_modificar";
	public final static String FUNCIONARIO_MODIFICAR_CONFIRMACION = "funcionario_modificar_confirmacion";
	public final static String FUNCIONARIO_CANCELAR_CONFIRMACION = "funcionario_cancelar_confirmacion";

	public final static String MAQUINARIA_AGREGAR = "maquinaria_agregar";
	public final static String MAQUINARIA_AGREGAR_CONFIRMACION = "maquinaria_agregar_confirmacion";
	public final static String MAQUINARIA_AGREGAR_CANCELAR = "maquinaria_agregar_cancelar";
	public final static String MAQUINARIA_ELIMINAR = "maquinaria_eliminar";
	public final static String MAQUINARIA_MODIFICAR = "maquinaria_modificar";
	public final static String MAQUINARIA_CANCELAR_MODIFICAR_CONFIRMACION = "maquinaria_cancelar_modificar_confirmacion";
	public final static String MAQUINARIA_MODIFICAR_CONFIRMACION = "maquinaria_modificar_confirmacion";
	public final static String MAQUINARIA_PRODUCE = "maquinaria_produce";

	public final static String PRODUCTO_AGREGAR = "producto_agregar";
	public final static String PRODUCTO_AGREGAR_CONFIRMACION = "producto_agregar_confirmacion";
	public final static String PRODUCTO_AGREGAR_CANCELAR = "producto_agregar_cancelar";
	
	public final static String PRODUCTO_ELIMINAR = "producto_eliminar";
	public final static String PRODUCTO_MODIFICAR = "producto_modificar";
	public final static String PRODUCTO_MODIFICAR_CONFIRMACION = "producto_modificar_confirmacion";
	public final static String PRODUCTO_MODIFICAR_CANCELAR = "producto_modificar_cancelar";

	public final static String MENSUALES_MOSTRAR = "mensuales_mostrar";
	public final static String MENSUALES_CREAR = "mensuales_crear";
	public final static String MENSUALES_AGREGAR = "mensuales_agregar";
	public final static String MENSUALES_MODIFICAR = "mensuales_modificar";
	public final static String MENSUALES_ELIMINAR = "mensuales_eliminar";
	public final static String MENSUALES_CONFIRMAR = "mensuales_confirmar";
	public final static String MENSUALES_AGREGAR_CONFIRMACION = "mensuales_agregar_confirmacion";
	public final static String MENSUALES_AGREGAR_CANCELAR = "mensuales_agregar_cancelar";
	
	public final static String CONFIRMAR_MOSTRAR = "confirmar_mostrar";
	public final static String CONFIRMAR_AGREGAR = "confirmar_agregar";
	public final static String CONFIRMAR_ELIMINAR = "confirmar_eliminar";
	public final static String CONFIRMAR_MOSTRAR_AGREGAR_FASE = "confirmar_mostrar_agregar_fase";
	public final static String CONFIRMAR_MOSTRAR_ELIMINAR_FASE  = "confirmar_mostrar_eliminar_fase";
	public final static String CONFIRMAR_MODIFICAR_LOTE  = "confirmar_modificar";
	public final static String CONFIRMAR_CANCELAR_MODIFICAR_LOTE  = "confirmar_cancelar_modificar";
	
	public final static String CONFIRMAR_CANCELAR_AGREGAR_LOTE = "confirmar_cancelar_agregar_lote";
	public final static String CONFIRMAR_AGREGAR_LOTE = "confirmar_agregar";
	
	public final static String AGREGAR_LOTE = "agregar_lote";
	public final static String MODIFICAR_LOTE = "modificar_lote";
	public final static String ELIMINAR_LOTE = "eliminar_lote";
	public final static String VERIFICAR_PLAN = "verificar_plan";
	public final static String CONFIRMAR_PLAN = "confirmar_plan";
	public final static String DESHACER_PLAN = "deshacer_plan";
	public final static String SET_LOTE_INDEX = "set_lote_index";

	public static enum PlanLabel {
		GRID_PANEL, PANEL_ERROR_LISTA_NO_CREADA, PANEL_INICIAL, PANEL_ERROR_ACTUALIZACION_PENDIENTE
	}
	
	/*public final static String GRID_PANEL = "grid_panel";
	public final static String BACK_PANEL = "back_panel";
	public final static String BACK_PANEL2 = "back_panel2";*/
	public final static String GRID_CONFIRMAR_PANEL = "grid_confirmar_panel";

	
	public final static HashMap <String,Integer> monthsmap = new HashMap<String,Integer>();
	static
	{
		monthsmap.put("Enero", 1);
		monthsmap.put("Febrero", 2);
		monthsmap.put("Marzo", 3);
		monthsmap.put("Abril", 4);
		monthsmap.put("Mayo", 5);
		monthsmap.put("Junio", 6);
		monthsmap.put("Julio", 7);
		monthsmap.put("Agosto", 8);
		monthsmap.put("Septiembre", 9);
		monthsmap.put("Octubre", 10);
		monthsmap.put("Noviembre", 11);
		monthsmap.put("Diciembre", 12);
	}
	
	public final static String months[] = new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio",
			"Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" };
	
	public static String[] singleArrayListToString(ArrayList<String> list) {

		String[] str = new String[list.size()];

		return list.toArray(str);

	}

	public static String[][] arrayListToString(
			ArrayList<ArrayList<String>> list) {

		String[][] strArray = new String[list.size()][100];

		for (int i = 0; i < strArray.length; i++) {
			String[] str = new String[list.get(i).size()];
			strArray[i] = list.get(i).toArray(str);
		}

		return strArray;

	}

	public static String[] arrayListToStringSelect(
			ArrayList<ArrayList<String>> list, int start, int end) {

		String[] strArray = new String[list.size()];

		// strArray[0] = "-- Seleccione las Maquinas --";
		for (int i = 0; i < strArray.length; i++) {
			String[] str = new String[list.get(i).subList(start, end).size()];
			strArray[i] = list.get(i).subList(start, end).toArray(str)[0];
		}

		return strArray;

	}

	public static String[] concat(String[] A, String[] B) {
		String[] C = new String[A.length + B.length];
		System.arraycopy(A, 0, C, 0, A.length);
		System.arraycopy(B, 0, C, A.length, B.length);

		return C;
	}

	public static JFrame getParentFrame(Component child) {
		Container c = child.getParent();
		while (c != null) {
			if (c instanceof JFrame) {
				return (JFrame) c;
			}
			c = c.getParent();
		}
		return null;
	}

	public static String[] getStartWeek(String year) {

		ArrayList<String> daylist = new ArrayList<String>();

		////System.out.println("year =" + year);
		DateTime date = new DateTime(year).withMonthOfYear(1).withDayOfYear(1);
		
		date = date.withWeekOfWeekyear(date.getWeekOfWeekyear()).withDayOfWeek(
				1);
		for (int i = 1; i <= 54; i++) {

			int years = date.year().get();
			if (!(years > Integer.valueOf(year))) {
				String monthStr = months[date.monthOfYear().getDateTime().getMonthOfYear()-1];
				String dayStr = date.dayOfMonth().getAsText();
				daylist.add(dayStr + "/" + monthStr + "/" + years);
				date = date.plusWeeks(1);
			}
		}
		return singleArrayListToString(daylist);
	}

	public static String getLastStartWeek(int day, String month, String year) {
		
		ArrayList<String> daylist = new ArrayList<String>();
		
		DateTime date = new DateTime(Integer.valueOf(year), monthsmap.get(month), day, 0, 0) ;
		
		date = date.minusWeeks(1);
		
		int years = date.year().get();
		String monthStr = months[date.monthOfYear().getDateTime().getMonthOfYear()-1];
		String dayStr = date.dayOfMonth().getAsText();
		return dayStr + "/" + monthStr + "/" + years;
	}
	
	public static void printMap(Map mp) {
		Iterator it = mp.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry pairs = (Map.Entry) it.next();
			//System.out.println(pairs.getKey() + " = " + pairs.getValue());
		}
	}
	
	

}
